package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Archives;
import com.ruoyi.system.service.IArchivesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 档案列表Controller
 *
 * @author ruoyi
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/archives")
public class ArchivesController extends BaseController
{
    @Autowired
    private IArchivesService archivesService;

    /**
     * 查询档案列表列表
     */
    @RequiresPermissions("system:archives:list")
    @GetMapping("/list")
    public TableDataInfo list(Archives archives)
    {
       startPage();
        List<Archives> list = archivesService.selectArchivesList(archives);
        return getDataTable(list);
    }

    /**
     * 导出档案列表列表
     */
    @RequiresPermissions("system:archives:export")
    @Log(title = "档案列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Archives archives)
    {
        List<Archives> list = archivesService.selectArchivesList(archives);
        ExcelUtil<Archives> util = new ExcelUtil<Archives>(Archives.class);
        util.exportExcel(response, list, "档案列表数据");
    }

    /**
     * 获取档案列表详细信息
     */
    @RequiresPermissions("system:archives:query")
    @GetMapping(value = "/{archivesId}")
    public AjaxResult getInfo(@PathVariable("archivesId") Long archivesId)
    {
        return success(archivesService.selectArchivesByArchivesId(archivesId));
    }

    /**
     * 新增档案列表
     */
    @RequiresPermissions("system:archives:add")
    @Log(title = "档案列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Archives archives)
    {
        return toAjax(archivesService.insertArchives(archives));
    }

    /**
     * 修改档案列表
     */
    @RequiresPermissions("system:archives:edit")
    @Log(title = "档案列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Archives archives)
    {
        return toAjax(archivesService.updateArchives(archives));
    }

    /**
     * 删除档案列表
     */
    @RequiresPermissions("system:archives:remove")
    @Log(title = "档案列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{archivesIds}")
    public AjaxResult remove(@PathVariable Long[] archivesIds)
    {
        return toAjax(archivesService.deleteArchivesByArchivesIds(archivesIds));
    }
}
